# -*- coding: utf-8 -*-

import time
from report import report_sxw
import pooler
from osv import osv
from tools.translate import _
import random
from datetime import datetime
import logging
        
class Parser(report_sxw.rml_parse):
    logging.getLoggerClass()
        
    def __init__(self, cr, uid, name, context):
        
        super(Parser, self).__init__(cr, uid, name, context=context)
        pool = pooler.get_pool(cr.dbname)
        self.gxn_list_obj = pool.get('ctsv.gxn.list')
        
        self.localcontext.update({
            'init': self._init,
            'gxn': self.get_gxn,
            'thuoc_dien': self.get_thuoc_dien,
            'doi_tuong': self.get_doi_tuong,
            'gender': self.get_gender,
            'get_logo': self.get_logo,
        })
    
    def _init(self, gxn):
        logging.info('----GXN ID : %s', gxn.id)
        self.gxn = self.gxn_list_obj.browse(self.cr, self.uid, gxn.id, context=None)
        self.thuoc_dien = ''
        if self.gxn.thuoc_dien == 'khongmiengiam':
            self.thuoc_dien = u'Không miễn giảm'
        if self.gxn.thuoc_dien == 'giamhocphi':
            self.thuoc_dien = u'Giảm học phí'
        if self.gxn.thuoc_dien == 'mienhocphi':
            self.thuoc_dien = u'Miễn học phí'    
    
        self.doi_tuong = ''
        if self.gxn.doi_tuong == 'khongmocoi':
            self.doi_tuong = u'Không mồ côi'
        if self.gxn.doi_tuong == 'mocoi':
            self.doi_tuong = u'Mồ côi'  
            
        gender = ''
        if self.gxn.gender == 'male':
            self.gender = u'Nam'
        if self.gxn.gender == 'female':
            self.gender = u'Nữ'    
        return True

    def get_gxn(self):
        return self.gxn
    def get_thuoc_dien(self):
        return self.thuoc_dien
    def get_doi_tuong(self):
        return self.doi_tuong
    def get_gender(self):
        return self.gender
    
    def get_logo(self):
        user = self.pool.get('res.users').browse(self.cr, self.uid, self.uid)
        logo = False
        if user.company_id:
            company = self.pool.get('res.company').browse(self.cr, self.uid, user.company_id.id)
            logo = company.logo
        return logo
    
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
